<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    template="/layout/template.xhtml">

<ui:define name="body">

    <h:form id="usuarioSearch" styleClass="edit">

        <rich:simpleTogglePanel label="Usuário: Filtro de Pesquisa" switchType="ajax">

            <s:div styleClass="tableControl" rendered="#{empty from}">
        		<s:link view="/resources/UsuarioEdit.xhtml"
		                    id="create"
		           propagation="none">
		            <h:graphicImage url="/img/add.png"/>
		            #{' '}
		            <h:outputLabel value="Novo"/>
		            <f:param name="usuarioId"/>
		            <f:param name="subGrupoId" value="#{usuarioList.subgrupo.id}"/>
		        </s:link>
		    </s:div>
            
            <s:decorate template="/layout/display.xhtml">
                <ui:define name="label">Nome</ui:define>
                <h:inputText id="nome" value="#{usuarioList.usuario.nome}"/>
            </s:decorate>
            
            <s:decorate template="/layout/display.xhtml">
                <ui:define name="label">E-mail</ui:define>
                <h:inputText id="email" value="#{usuarioList.usuario.email}"/>
            </s:decorate>
            
            <s:decorate id="status" template="/layout/display.xhtml">
				<ui:define name="label">Status</ui:define>
            	<h:selectOneRadio id="status" value="#{usuarioList.usuario.status}" styleClass="radio" required="true">
                    <f:selectItem itemLabel="Ativo" itemValue="Ativo"/>
                    <f:selectItem itemLabel="Inativo" itemValue="Inativo"/>
                </h:selectOneRadio>
			</s:decorate>
            
            <s:decorate template="/layout/display.xhtml">
                <ui:define name="label">Combinar campos?</ui:define>
                <h:selectOneRadio id="logic" value="#{usuarioList.restrictionLogicOperator}" styleClass="radio">
                    <f:selectItem itemLabel="Sim" itemValue="and"/>
                    <f:selectItem itemLabel="Não" itemValue="or"/>
                </h:selectOneRadio>
            </s:decorate>
            
            <s:decorate template="/layout/display.xhtml">
				<h:commandButton id="search" value="Pesquisar" action="/resources/UsuarioList.xhtml"/>
            	<s:button id="reset" value="Limpar" includePageParams="false"/>
			</s:decorate>
        </rich:simpleTogglePanel>

    </h:form>

	<br clear="left"/>

    <rich:panel>
        <f:facet name="header">Usuário: Resultados da Pesquisa (#{empty usuarioList.resultList ? 0 : (usuarioList.paginated ? usuarioList.resultCount : usuarioList.resultList.size)})</f:facet>
    <div class="results" id="usuarioList">

    <h:outputText value="A pesquisa não retornou nenhum resultado."
               rendered="#{empty usuarioList.resultList}"/>

    <rich:dataTable id="usuarioList"
                var="_usuario"
              value="#{usuarioList.resultList}"
           rendered="#{not empty usuarioList.resultList}"
         rowClasses="odd,even"
               rows="20">
        <h:column>
            <f:facet name="header">
                <ui:include src="/layout/sort.xhtml">
                    <ui:param name="entityList" value="#{usuarioList}"/>
                    <ui:param name="propertyLabel" value="Nome"/>
                    <ui:param name="propertyPath" value="usuario.nome"/>
                </ui:include>
            </f:facet>
            <h:outputText value="#{_usuario.nome}"/>
        </h:column>
        <h:column>
            <f:facet name="header">
                <ui:include src="/layout/sort.xhtml">
                    <ui:param name="entityList" value="#{usuarioList}"/>
                    <ui:param name="propertyLabel" value="E-mail"/>
                    <ui:param name="propertyPath" value="usuario.email"/>
                </ui:include>
            </f:facet>
            <h:outputText value="#{_usuario.email}"/>
        </h:column>
        <h:column>
            <f:facet name="header">
                <ui:include src="/layout/sort.xhtml">
                    <ui:param name="entityList" value="#{usuarioList}"/>
                    <ui:param name="propertyLabel" value="Data de Cadastro"/>
                    <ui:param name="propertyPath" value="usuario.dataCadastro.time"/>
                </ui:include>
            </f:facet>
            <h:outputText value="#{_usuario.dataCadastro.time}"/>
        </h:column>
        <h:column>
            <f:facet name="header">
                <ui:include src="/layout/sort.xhtml">
                    <ui:param name="entityList" value="#{usuarioList}"/>
                    <ui:param name="propertyLabel" value="Status"/>
                    <ui:param name="propertyPath" value="usuario.status"/>
                </ui:include>
            </f:facet>
            <h:outputText value="#{_usuario.status}"/>
        </h:column>
        <rich:column styleClass="action">
            <f:facet name="header">Opções</f:facet>
            <s:link view="/resources/#{empty from ? 'Usuario' : from}.xhtml"
                   value="#{empty from ? 'Ver' : 'Selecionar'}"
             propagation="#{empty from ? 'none' : 'default'}"
                      id="usuarioViewId">
                <f:param name="usuarioId"
                        value="#{_usuario.id}"/>
            </s:link>
            #{' '}
            <s:link view="/resources/UsuarioEdit.xhtml"
                   value="Editar"
             propagation="none"
                      id="usuarioEdit"
                rendered="#{empty from}">
                <f:param name="usuarioId"
                        value="#{_usuario.id}"/>
            </s:link>
        </rich:column>
    </rich:dataTable>

    </div>
    </rich:panel>

    <div class="tableControl">

        <s:link view="/resources/UsuarioList.xhtml"
            rendered="#{usuarioList.previousExists}"
               value="#{messages.left}#{messages.left} #{messages.firstPage}"
                  id="firstPage">
          <f:param name="firstResult" value="0"/>
        </s:link>

        <s:link view="/resources/UsuarioList.xhtml"
            rendered="#{usuarioList.previousExists}"
               value="#{messages.left} #{messages.previousPage}"
                  id="previousPage">
            <f:param name="firstResult"
                    value="#{usuarioList.previousFirstResult}"/>
        </s:link>

        <s:link view="/resources/UsuarioList.xhtml"
            rendered="#{usuarioList.nextExists}"
               value="#{messages.nextPage} #{messages.right}"
                  id="nextPage">
            <f:param name="firstResult"
                    value="#{usuarioList.nextFirstResult}"/>
        </s:link>

        <s:link view="/resources/UsuarioList.xhtml"
            rendered="#{usuarioList.nextExists}"
               value="#{messages.lastPage} #{messages.right}#{messages.right}"
                  id="lastPage">
            <f:param name="firstResult"
                    value="#{usuarioList.lastFirstResult}"/>
        </s:link>

    </div>

</ui:define>

</ui:composition>
